#!/bin/bash

# Dubbo + Nacos 示例停止脚本

echo "========================================="
echo "  停止 Dubbo + Nacos 示例"
echo "========================================="

# 停止 Provider
if [ -f provider.pid ]; then
    PROVIDER_PID=$(cat provider.pid)
    if ps -p $PROVIDER_PID > /dev/null 2>&1; then
        echo "停止 Provider (PID: $PROVIDER_PID)..."
        kill $PROVIDER_PID
        echo "✅ Provider 已停止"
    else
        echo "⚠️  Provider 未运行"
    fi
    rm provider.pid
else
    echo "⚠️  找不到 Provider PID 文件"
fi

# 停止 Consumer
if [ -f consumer.pid ]; then
    CONSUMER_PID=$(cat consumer.pid)
    if ps -p $CONSUMER_PID > /dev/null 2>&1; then
        echo "停止 Consumer (PID: $CONSUMER_PID)..."
        kill $CONSUMER_PID
        echo "✅ Consumer 已停止"
    else
        echo "⚠️  Consumer 未运行"
    fi
    rm consumer.pid
else
    echo "⚠️  找不到 Consumer PID 文件"
fi

echo ""
echo "========================================="
echo "  所有服务已停止"
echo "========================================="

